//
//  ContainerViewController.m
//  ShangHaiTuJI
//
//  Created by xiaoxiangtuji on 2017/7/29.
//  Copyright © 2017年 xiaoxiangtuji. All rights reserved.
//

#import "ContainerViewController.h"
#import "CompetionTopView.h"
#import "CompetionInformViewController.h"
#import "CompetionReviewViewController.h"
#import "UIScrollView+Pages.h"
@interface ContainerViewController ()<UIScrollViewDelegate,CompetionDelegate>

@property (nonatomic,strong) UIScrollView *scrollView;

@end

@implementation ContainerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    CompetionTopView *titleView = [[CompetionTopView alloc] initWithFrame:CGRectMake(0, 0, scaleLeftAndRight(150),30)];
    titleView.delegate = self;
    self.navigationItem.titleView = titleView;
    [self.view addSubview:self.scrollView];
    CompetionInformViewController *inforVC = [[CompetionInformViewController alloc] init];
    [self addChildViewController:inforVC];
    CompetionReviewViewController *reviewVC = [[CompetionReviewViewController alloc] init];
    [self addChildViewController:reviewVC];
    inforVC.view.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
    [self.scrollView addSubview:inforVC.view];
    reviewVC.view.frame = CGRectMake(WIDTH, 0, WIDTH, HEIGHT);
    [self.scrollView addSubview:reviewVC.view];

}
- (void)selectedGroup:(NSInteger)type {
    if (type == 1) {
        [_scrollView setPageX:0 animated:NO];
    }else{
        [_scrollView setPageX:1 animated:NO];
    }
}




- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    if (self.scrollView == scrollView) {
        NSInteger page = scrollView.contentOffset.x / WIDTH;
        [((CompetionTopView *)self.navigationItem.titleView) switchToTab:page + 1];
    }
}

- (UIScrollView *)scrollView {
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc] init];
        _scrollView.frame = self.view.bounds;
        _scrollView.pagingEnabled = YES;
        _scrollView.delegate = self;
        _scrollView.showsHorizontalScrollIndicator = NO;
        _scrollView.showsVerticalScrollIndicator = NO;
        _scrollView.bounces = NO;
        _scrollView.contentSize = CGSizeMake(WIDTH * 2, HEIGHT - 64);
    }
    return _scrollView;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
